package com.wangp.mywrite.inwork.mapstruct;

import org.mapstruct.factory.Mappers;
import org.springframework.beans.BeanUtils;

/***
 * @author wangpeng
 * @since 2022-09-01  16:37
 */
public class Main {

    public static void main(String[] args) {
        User user = buildUser();
        UserReproducer userReproducer = new UserReproducer();

        calCostTimeByBeanUtil(user, userReproducer, 500_0000);
        calCostTimeByMapStruct(user, userReproducer, 1);

        System.out.println(userReproducer);
    }


    private static void calCostTimeByBeanUtil(User user, UserReproducer userReproducer, int count) {
        long startTime = System.currentTimeMillis();
        for (int i = 0; i < count; i++) {
        BeanUtils.copyProperties(user, userReproducer);
        }
        System.out.println("BeanUtils cost time = " + (System.currentTimeMillis() - startTime) + " ms");
    }

    private static void calCostTimeByMapStruct(User user, UserReproducer userReproducer, int count) {

        long startTime = System.currentTimeMillis();
        for (int i = 0; i < count; i++) {
            userReproducer = IUserMapper.INSTANCE.copyUser(user);
        }
        System.out.println("MapStruct cost time = " + (System.currentTimeMillis() - startTime) + " ms");
    }


    private static User buildUser() {
        User user = new User();
        user.setId(1L);
        user.setAge(12);
        user.setName("XiaoMing");
        user.setUname("XiaoMingPlus");
        return user;
    }

}
